package function;


/**
 * @describe 显示业主的所有信息，核对好信息后办理退房
 */

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import UserDatabase.UserDatabase;
import login.LoginFrame;

public class CheckOutFrame extends JFrame{

	String [] tableHead;
	String [][] user;
	JTable table;
	JLabel l_tip;
	JButton b_confirm,b_cancel;
	UserDatabase udb = new UserDatabase();
	String SQL,Username;
	
	public CheckOutFrame(String SQL,String Username) {
		this.setSize(800,500);
		this.setTitle("退房");
		this.setLocation(500,150);
		this.SQL = SQL;
		this.Username = Username;
		init();
		this.setVisible(true);
	}
	
	public void init() {
		udb.setSQL(SQL);
		user = udb.getRecord();
		tableHead = udb.getColumnName();
		table = new JTable(user,tableHead);
		
		l_tip = new JLabel("请确认信息",JLabel.CENTER);
		
		b_confirm = new JButton("确认");
		b_confirm.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				JPanel f = new JPanel();
				udb.delete(Username);
				JOptionPane.showMessageDialog(f,"退房成功！","提示框",JOptionPane.WARNING_MESSAGE);	
				new LoginFrame();
				setVisible(false);
			}
			
		});
		
		b_cancel = new JButton("取消");
		b_cancel.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				new UserFrame(Username);
				setVisible(false);
			}
			
		});
		
		JPanel p = new JPanel();
		p.setLayout(new GridLayout(1,1,5,5));
		p.add(l_tip);
		
		JScrollPane sp = new JScrollPane(table);
		
		JPanel p_bottom = new JPanel();
		p_bottom.setLayout(new GridLayout(1,1,8,8));
		p_bottom.add(b_confirm);
		p_bottom.add(b_cancel);
		
		this.add(p,BorderLayout.NORTH);
		this.add(sp,BorderLayout.CENTER);
		this.add(p_bottom,BorderLayout.SOUTH);
	}
		
}
